{% extends 'base.html' %}

{% block title %}资产分配 - 固定资产管理系统{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-6">
        <h2>资产分配</h2>
        
        <div class="card mb-3">
            <div class="card-header">
                <h5>{{ asset.name }}</h5>
            </div>
            <div class="card-body">
                <p><strong>资产编号:</strong> {{ asset.asset_number }}</p>
                <p><strong>当前状态:</strong>
                    {% if asset.status == 'idle' %}<span class="badge bg-secondary">闲置</span>
                    {% elif asset.status == 'in_use' %}<span class="badge bg-success">在用</span>
                    {% elif asset.status == 'maintenance' %}<span class="badge bg-warning">维修中</span>
                    {% elif asset.status == 'scrapped' %}<span class="badge bg-danger">已报废</span>
                    {% endif %}
                </p>
                <p><strong>所属部门:</strong> {{ asset.department.name|default:'-' }}</p>
                <p><strong>使用人:</strong> {% if asset.user %}{{ asset.user.username }}{% else %}-{% endif %}</p>
            </div>
        </div>
        
        <form method="post">
            {% csrf_token %}
            
            <div class="mb-3">
                <label for="department" class="form-label">分配到部门</label>
                <select class="form-select" id="department" name="department">
                    <option value="">请选择部门</option>
                    {% for department in departments %}
                        <option value="{{ department.id }}" {% if asset.department_id == department.id %}selected{% endif %}>
                            {{ department.name }}
                        </option>
                    {% endfor %}
                </select>
            </div>
            
            <div class="mb-3">
                <label for="user" class="form-label">分配给用户</label>
                <select class="form-select" id="user" name="user">
                    <option value="">请选择用户</option>
                    {% for user in users %}
                        <option value="{{ user.id }}" {% if asset.user_id == user.id %}selected{% endif %}>
                            {{ user.username }}
                        </option>
                    {% endfor %}
                </select>
            </div>
            
            <div class="mb-3">
                <label for="description" class="form-label">备注</label>
                <textarea class="form-control" id="description" name="description" rows="3"></textarea>
            </div>
            
            <div class="mb-3">
                <button type="submit" class="btn btn-primary">确认分配</button>
                <a href="{% url 'assets:asset_detail' asset.pk %}" class="btn btn-secondary">取消</a>
            </div>
        </form>
    </div>
</div>
{% endblock %}